
// 功能: 打开当前目录下的文件(open file1)
void open()
{
int i, inum, mode, filenum,chk;
if(argc != 2)
{
printf("command open must have one args. \n");
return ;
}
for(i = 0; i < INODENUM; i++)
if((inode_array[i].inum > 0) &&
(inode_array[i].type == '-') &&
!strcmp(inode_array[i].file_name,argv[1]))
break;
if(i == INODENUM)
{
printf("The file you want to open doesn't exsited.\n");
return ;
}
inum = i;
chk=check(i);
if(chk!=1)
{
printf("This file is not your !\n");
return ;
}
printf("Please input open mode:(1: read, 2: write, 3: read and write):");
scanf("%d", &mode);
gets(temp);
if((mode < 1) || (mode > 3))
{
printf("Open mode is wrong.\n");
return;
}
for(i = 0; i < FILENUM; i++)
if(file_array[i].inum < 0) break;
if(i == FILENUM)
{
printf("The file table is full, please close some file.\n");
return ;
}
filenum = i;
file_array[filenum].inum = inum;
strcpy(file_array[filenum].file_name, inode_array[inum].file_name);
file_array[filenum].mode = mode;
file_array[filenum].offset = 0;
printf("Open file %s by ", file_array[filenum].file_name);
if(mode == 1) printf("read only.\n");
else if(mode == 2) printf("write only.\n");
else printf("read and write.\n");
}